import * as types from "../types/mineTypes";

const initialState = {
  loading: false,
  initing: true,
  error: undefined,
  storeInfoDone: false,
  storeInfo: {},
  userInfo: {},
  hasLoggedin: false,
};

export default function homeReducer(state = initialState, action) {
  switch (action.type) {
    case types.MINE_USERINFO_DONE:
      return {
        ...state,
        initing: false,
        loading: false,
        hasLoggedin: true,
        userInfo: action.userInfo,
      };
    case types.MINE_USERINFO_ERROR:
      return {
        ...state,
        initing: false,
        loading: false,
        error: action.error,
      };
    case types.MINE_STOREINFO_DONE:
      return {
        ...state,
        initing: false,
        loading: false,
        storeInfoDone: true,
        storeInfo: action.storeInfo,
      };
    case types.MINE_STOREINFO_ERROR:
      return {
        ...state,
        initing: false,
        loading: false,
        error: action.error,
      };
    case types.MINE_LOGOUT:
      return {
        ...initialState,
      };
    default:
      return state;
  }
}
